package com.example.plantuml.config;

import com.example.plantuml.tools.CallChainManager;
import com.example.plantuml.tools.PlantUmlGenerator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@EnableAspectJAutoProxy
public class AopConfig {
    @Value("${request.trace.max-records:10}")
    private int requestTraceMaxRecodes;
    @Value("${request.trace.min-duration-ms:0}")  // 默认0毫秒，即全部记录
    private long minDurationMs;

    //    @Bean
//    public BaseRequestTraceAspect baseRequestTraceAspect() {
//        return new BaseRequestTraceAspect();
//    }

    @Bean
    public CallChainManager callChainManager() {
        return new CallChainManager(requestTraceMaxRecodes,minDurationMs);
    }

    @Bean
    public PlantUmlGenerator plantUmlGenerator() {
        return new PlantUmlGenerator();
    }

//    @Value("${request.trace.base-packages}")
//    private String basePackages;
//
//    @Bean
//    public final String pointcutExpression() {
//        return Arrays.stream(basePackages.split(",\\s*"))
//                .map(pkg -> "execution(* " + pkg + "..*.*(..))")
//                .collect(Collectors.joining(" || "));
//    }
//    @Bean
//    public AspectJExpressionPointcutAdvisor configurabledvisor(RequestTraceAspect traceAspect) {
//        AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
//        advisor.setExpression(pointcutExpression());
//        advisor.setAdvice(traceAspect);
//        return advisor;
//    }
}
